/**
 * Created by fifths on 17-8-14.
 */

import {Injectable} from '@angular/core';


@Injectable()
export class LocalStorageService {

  constructor() {
  }

  // 设置当前所在的小程序
  setNowApplet(item) {
    delete item.config;
    delete item.pay_key;
    delete item.AppSecret;
    const data = JSON.stringify(item);
    localStorage.setItem('nowApplet', data);
  }

  // 获取当前所在的小程序
  getNowApplet() {
    const data = localStorage.getItem('nowApplet');
    return JSON.parse(data);
  }


  // 设置当前member登录用户信息
  setUserInfo(item) {
    const data = JSON.stringify(item);
    localStorage.setItem('userInfo', data);
  }

  // 获取当前member登录用户信息
  getUserInfo() {
    const data = localStorage.getItem('userInfo');
    return JSON.parse(data);
  }

  // 设置当前admin登录用户信息
  setAdminInfo(item) {
    const data = JSON.stringify(item);
    localStorage.setItem('adminInfo', data);
  }

  // 获取当前admin登录用户信息
  getAdminInfo() {
    const data = localStorage.getItem('adminInfo');
    return JSON.parse(data);
  }

  // 设置token
  setToken(item) {
    const data = JSON.stringify(item);
    localStorage.setItem('token', data);
  }

  // 获取token
  getToken() {
    const data = localStorage.getItem('token');
    return JSON.parse(data);
  }

  //设置当期前小程序管理员的授权状态
  setAppletToken(item){
    const data = JSON.stringify(item);
    localStorage.setItem('appletToken', data);
  }

  // 清除当前小程序的管理员的授权状态
  clearAppletToken() {
    localStorage.removeItem('appletToken');
  }

  // 获取token
  getAppletToken() {
    const data = localStorage.getItem('appletToken');
    return JSON.parse(data);
  }

  // 清除所有信息
  clearAll() {
    localStorage.clear();
  }

  // 清除小程序信息
  clearNowAppleto() {
    localStorage.removeItem('nowApplet');
  }

  // 清除用户信息
  clearUserInfo() {
    localStorage.removeItem('userInfo');
  }

  // 清除token
  clearToken() {
    localStorage.removeItem('token');
  }

  // 获得店铺ID
  getShopId() {
    const data = localStorage.getItem('shopId');
    return  Number(data);
  }

  // 设置当前店铺
  setShop(item) {
    const data = JSON.stringify(item);
    localStorage.setItem('shopInfo', data);
  }

  // 获取当前店铺
  getShop() {
    const data = localStorage.getItem('shopInfo');
    return JSON.parse(data);
  }
}
